#include "cubes.h"
#include "ui_cubes.h"
#include "QPainter"
#include "QTimer"
#include "QKeyEvent"

void Cubes::init()
{
    vCubeRect1.resize(4);
    for(int i=0;i<vCubeRect1.size();i++)
    {
        QRect rect(250+25*i,25,25,25);
        vCubeRect1[vCubeRect1.size()-1-i]=rect;
    }//----
    CubeLeft1 = vCubeRect1[3];
    CubeBottom1 = vCubeRect1[2];
    CubeRight1 = vCubeRect1.first();
    CubeTop1 = vCubeRect1[1];
    vCubeRect2.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0)
        {
            QRect rect(275,25,25,25);
            vCubeRect2[vCubeRect2.size()-1-i]=rect;
        }
        else
        {
            QRect rect(250+25*(i-1),50,25,25);
            vCubeRect2[vCubeRect2.size()-1-i]=rect;
        }
    }//-=-
    CubeLeft2 = vCubeRect2[2];
    CubeBottom2 = vCubeRect2[1];
    CubeRight2 = vCubeRect2.first();
    CubeTop2 = vCubeRect2[3];
    vCubeRect3.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i<2)
        {
            QRect rect(275+25*i,25,25,25);
            vCubeRect3[vCubeRect3.size()-1-i]=rect;
        }
        else
        {
            QRect rect(275+25*(i-2),50,25,25);
            vCubeRect3[vCubeRect3.size()-1-i]=rect;
        }
    }//==
    CubeLeft3 = vCubeRect3[1];
    CubeBottom3 = vCubeRect3.first();
    CubeRight3 = vCubeRect3[2];
    CubeTop3 = vCubeRect3[3];
    vCubeRect4.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0)
        {
            QRect rect(275,25,25,25);
            vCubeRect4[vCubeRect4.size()-1-i]=rect;
        }
        if(i==1||i==2)
        {
            QRect rect(275+25*(i-1),50,25,25);
            vCubeRect4[vCubeRect4.size()-1-i]=rect;
        }
        if(i==3)
        {
            QRect rect(300,75,25,25);
            vCubeRect4[vCubeRect4.size()-1-i]=rect;
        }
    }//=-_
    CubeLeft4 = vCubeRect4[2];
    CubeBottom4 = vCubeRect4.first();
    CubeRight4 = vCubeRect4[1];
    CubeTop4 = vCubeRect4[3];
    vCubeRect5.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0)
        {
            QRect rect(275,25,25,25);
            vCubeRect5[vCubeRect5.size()-1-i]=rect;
        }
        if(i==1)
        {
            QRect rect(275,50,25,25);
            vCubeRect5[vCubeRect5.size()-1-i]=rect;
        }
        if(i==3||i==2)
        {
            QRect rect(275+(i-2)*25,75,25,25);
            vCubeRect5[vCubeRect5.size()-1-i]=rect;
        }
    }//=__
    CubeLeft5 = vCubeRect5[2];
    CubeBottom5 = vCubeRect5[1];
    CubeRight5 = vCubeRect5.first();
    CubeTop5 = vCubeRect5[3];
    vCubeRect6.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0)
        {
            QRect rect(275,25,25,25);
            vCubeRect6[vCubeRect6.size()-1-i]=rect;
        }
        if(i==1)
        {
            QRect rect(275,50,25,25);
            vCubeRect6[vCubeRect6.size()-1-i]=rect;
        }
        if(i==3||i==2)
        {
            QRect rect(250+(i-2)*25,75,25,25);
            vCubeRect6[vCubeRect6.size()-1-i]=rect;
        }
    }//__=
    CubeLeft6 = vCubeRect6[1];
    CubeBottom6 = vCubeRect6.first();
    CubeRight6 = vCubeRect6[2];
    CubeTop6 = vCubeRect6[3];
    vCubeRect7.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0)
        {
            QRect rect(275,25,25,25);
            vCubeRect7[vCubeRect7.size()-1-i]=rect;
        }
        if(i==1||i==2)
        {
            QRect rect(250+(25*(i-1)),50,25,25);
            vCubeRect7[vCubeRect7.size()-1-i]=rect;
        }
        if(i==3)
        {
            QRect rect(250,75,25,25);
            vCubeRect7[vCubeRect7.size()-1-i]=rect;
        }
    }
    CubeLeft7 = vCubeRect7[2];
    CubeBottom7 = vCubeRect7.first();
    CubeRight7 = vCubeRect7[1];
    CubeTop7 = vCubeRect7[3];
    vCubeRect8.resize(4);
    for(int i=0;i<4;i++)
    {
        QRect rect(275,25+25*i,25,25);
        vCubeRect8[vCubeRect8.size()-1-i]=rect;
    }
    CubeLeft8 = vCubeRect8[1];
    CubeBottom8 = vCubeRect8.first();
    CubeRight8 = vCubeRect8[2];
    CubeTop8 = vCubeRect8[3];
    vCubeRect9.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0)
        {
            QRect rect(275,25,25,25);
            vCubeRect9[vCubeRect9.size()-1-i]=rect;
        }
        if(i==1||i==2)
        {
            QRect rect(275+25*(i-1),50,25,25);
            vCubeRect9[vCubeRect9.size()-1-i]=rect;
        }
        if(i==3)
        {
            QRect rect(275,75,25,25);
            vCubeRect9[vCubeRect9.size()-1-i]=rect;
        }
    }
    CubeLeft9 = vCubeRect9[2];
    CubeBottom9 = vCubeRect9.first();
    CubeRight9 = vCubeRect9[1];
    CubeTop9 = vCubeRect9[3];
    vCubeRect10.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0||i==1||i==2)
        {
            QRect rect(250+25*i,25,25,25);
            vCubeRect10[vCubeRect10.size()-1-i]=rect;
        }
        if(i==3)
        {
            QRect rect(275,50,25,25);
            vCubeRect10[vCubeRect10.size()-1-i]=rect;
        }
    }
    CubeLeft10 = vCubeRect10[3];
    CubeBottom10 = vCubeRect10.first();
    CubeRight10 = vCubeRect10[1];
    CubeTop10 = vCubeRect10[2];
    vCubeRect11.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0)
        {
            QRect rect(275,25,25,25);
            vCubeRect11[vCubeRect11.size()-1-i]=rect;
        }
        if(i==1||i==2)
        {
            QRect rect(250+25*(i-1),50,25,25);
            vCubeRect11[vCubeRect11.size()-1-i]=rect;
        }
        if(i==3)
        {
            QRect rect(275,75,25,25);
            vCubeRect11[vCubeRect11.size()-1-i]=rect;
        }
    }
    CubeLeft11 = vCubeRect11[2];
    CubeBottom11 = vCubeRect11.first();
    CubeRight11 = vCubeRect11[1];
    CubeTop11 = vCubeRect11[3];
    vCubeRect12.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0||i==1)
        {
            QRect rect(275+25*i,25,25,25);
            vCubeRect12[vCubeRect12.size()-1-i]=rect;
        }
        if(i==3||i==2)
        {
            QRect rect(250+25*(i-2),50,25,25);
            vCubeRect12[vCubeRect12.size()-1-i]=rect;
        }
    }
    CubeLeft12 = vCubeRect12[1];
    CubeBottom12 = vCubeRect12.first();
    CubeRight12 = vCubeRect12[2];
    CubeTop12 = vCubeRect12[3];
    vCubeRect13.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0||i==1||i==2)
        {
            QRect rect(250+25*i,25,25,25);
            vCubeRect13[vCubeRect13.size()-1-i]=rect;
        }
        if(i==3)
        {
            QRect rect(250,50,25,25);
            vCubeRect13[vCubeRect13.size()-1-i]=rect;
        }
    }
    CubeLeft13 = vCubeRect13[3];
    CubeBottom13 = vCubeRect13.first();
    CubeRight13 = vCubeRect13[1];
    CubeTop13 = vCubeRect13[2];
    vCubeRect14.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0||i==1)
        {
            QRect rect(250+25*i,25,25,25);
            vCubeRect14[vCubeRect14.size()-1-i]=rect;
        }
        if(i==2)
        {
            QRect rect(275,50,25,25);
            vCubeRect14[vCubeRect14.size()-1-i]=rect;
        }
        if(i==3)
        {
            QRect rect(275,75,25,25);
            vCubeRect14[vCubeRect14.size()-1-i]=rect;
        }
    }
    CubeLeft14 = vCubeRect14[3];
    CubeBottom14 = vCubeRect14.first();
    CubeRight14 = vCubeRect14[1];
    CubeTop14 = vCubeRect14[2];
    vCubeRect15.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0)
        {
            QRect rect(300,25,25,25);
            vCubeRect15[vCubeRect15.size()-1-i]=rect;
        }
        if(i==3||i==1||i==2)
        {
            QRect rect(250+25*(i-1),50,25,25);
            vCubeRect15[vCubeRect15.size()-1-i]=rect;
        }
    }
    CubeLeft15 = vCubeRect15[2];
    CubeBottom15 = vCubeRect15[1];
    CubeRight15 = vCubeRect15.first();
    CubeTop15 = vCubeRect15[3];
    vCubeRect16.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0)
        {
            QRect rect(250,25,25,25);
            vCubeRect16[vCubeRect16.size()-1-i]=rect;
        }
        if(i==3||i==1||i==2)
        {
            QRect rect(250+25*(i-1),50,25,25);
            vCubeRect16[vCubeRect16.size()-1-i]=rect;
        }
    }
    CubeLeft16 = vCubeRect16[2];
    CubeBottom16 = vCubeRect16[1];
    CubeRight16 = vCubeRect16.first();
    CubeTop16 = vCubeRect16[3];
    vCubeRect17.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0||i==1)
        {
            QRect rect(275+25*i,25,25,25);
            vCubeRect17[vCubeRect17.size()-1-i]=rect;
        }
        if(i==2)
        {
            QRect rect(275,50,25,25);
            vCubeRect17[vCubeRect17.size()-1-i]=rect;
        }
        if(i==3)
        {
            QRect rect(275,75,25,25);
            vCubeRect17[vCubeRect17.size()-1-i]=rect;
        }
    }
    CubeLeft17 = vCubeRect17[1];
    CubeBottom17 = vCubeRect17.first();
    CubeRight17 = vCubeRect17[2];
    CubeTop17 = vCubeRect17[3];
    vCubeRect18.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0||i==1||i==2)
        {
            QRect rect(250+25*i,25,25,25);
            vCubeRect18[vCubeRect18.size()-1-i]=rect;
        }
        if(i==3)
        {
            QRect rect(300,50,25,25);
            vCubeRect18[vCubeRect18.size()-1-i]=rect;
        }
    }
    CubeLeft18 = vCubeRect18[3];
    CubeBottom18 = vCubeRect18.first();
    CubeRight18 = vCubeRect18[1];
    CubeTop18 = vCubeRect18[2];
    vCubeRect19.resize(4);
    for(int i=0;i<4;i++)
    {
        if(i==0||i==1)
        {
            QRect rect(250+25*i,25,25,25);
            vCubeRect19[vCubeRect19.size()-1-i]=rect;
        }
        if(i==3||i==2)
        {
            QRect rect(275+25*(i-2),50,25,25);
            vCubeRect19[vCubeRect19.size()-1-i]=rect;
        }
    }
    CubeLeft19 = vCubeRect19[3];
    CubeBottom19 = vCubeRect19[1];
    CubeRight19 = vCubeRect19.first();
    CubeTop19 = vCubeRect19[2];
    qsrand((time_t)time(0));
    if(!blsRun)
        now = qrand()%19;
    else
        now = next;
    next = qrand()%19;
    switch(now)
    {
        case 0:
        {
            vCubeRect = vCubeRect1;
            CubeLeft = CubeLeft1;
            CubeBottom = CubeBottom1;
            CubeRight = CubeRight1;
            CubeTop = CubeTop1;
            cCube = 1;
            break;
        }
        case 1:
        {
            vCubeRect = vCubeRect2;
            CubeLeft = CubeLeft2;
            CubeBottom = CubeBottom2;
            CubeRight = CubeRight2;
            CubeTop = CubeTop2;
            cCube = 2;
            break;
        }
        case 2:
        {
            vCubeRect = vCubeRect3;
            CubeLeft = CubeLeft3;
            CubeBottom = CubeBottom3;
            CubeRight = CubeRight3;
            CubeTop = CubeTop3;
            cCube = 3;
            break;
        }
        case 3:
        {
            vCubeRect = vCubeRect4;
            CubeLeft = CubeLeft4;
            CubeBottom = CubeBottom4;
            CubeRight = CubeRight4;
            CubeTop = CubeTop4;
            cCube = 4;
            break;
        }
        case 4:
        {
            vCubeRect = vCubeRect5;
            CubeLeft = CubeLeft5;
            CubeBottom = CubeBottom5;
            CubeRight = CubeRight5;
            CubeTop = CubeTop5;
            cCube = 5;
            break;
        }
        case 5:
        {
            vCubeRect = vCubeRect6;
            CubeLeft = CubeLeft6;
            CubeBottom = CubeBottom6;
            CubeRight = CubeRight6;
            CubeTop = CubeTop6;
            cCube = 6;
            break;
        }
        case 6:
        {
            vCubeRect = vCubeRect7;
            CubeLeft = CubeLeft7;
            CubeBottom = CubeBottom7;
            CubeRight = CubeRight7;
            CubeTop = CubeTop7;
            cCube = 7;
            break;
        }
        case 7:
        {
            vCubeRect = vCubeRect8;
            CubeLeft = CubeLeft8;
            CubeBottom = CubeBottom8;
            CubeRight = CubeRight8;
            CubeTop = CubeTop8;
            cCube = 8;
            break;
        }
        case 8:
        {
            vCubeRect = vCubeRect9;
            CubeLeft = CubeLeft9;
            CubeBottom = CubeBottom9;
            CubeRight = CubeRight9;
            CubeTop = CubeTop9;
            cCube = 9;
            break;
        }
        case 9:
        {
            vCubeRect = vCubeRect10;
            CubeLeft = CubeLeft10;
            CubeBottom = CubeBottom10;
            CubeRight = CubeRight10;
            CubeTop = CubeTop10;
            cCube = 10;
            break;
        }
        case 10:
        {
            vCubeRect = vCubeRect11;
            CubeLeft = CubeLeft11;
            CubeBottom = CubeBottom11;
            CubeRight = CubeRight11;
            CubeTop = CubeTop11;
            cCube = 11;
            break;
        }
        case 11:
        {
            vCubeRect = vCubeRect12;
            CubeLeft = CubeLeft12;
            CubeBottom = CubeBottom12;
            CubeRight = CubeRight12;
            CubeTop = CubeTop12;
            cCube = 12;
            break;
        }
        case 12:
        {
            vCubeRect = vCubeRect13;
            CubeLeft = CubeLeft13;
            CubeBottom = CubeBottom13;
            CubeRight = CubeRight13;
            CubeTop = CubeTop13;
            cCube = 13;
            break;
        }
        case 13:
        {
            vCubeRect = vCubeRect14;
            CubeLeft = CubeLeft14;
            CubeBottom = CubeBottom14;
            CubeRight = CubeRight14;
            CubeTop = CubeTop14;
            cCube = 14;
            break;
        }
        case 14:
        {
            vCubeRect = vCubeRect15;
            CubeLeft = CubeLeft15;
            CubeBottom = CubeBottom15;
            CubeRight = CubeRight15;
            CubeTop = CubeTop15;
            cCube = 15;
            break;
        }
        case 15:
        {
            vCubeRect = vCubeRect16;
            CubeLeft = CubeLeft16;
            CubeBottom = CubeBottom16;
            CubeRight = CubeRight16;
            CubeTop = CubeTop16;
            cCube = 16;
            break;
        }
        case 16:
        {
            vCubeRect = vCubeRect17;
            CubeLeft = CubeLeft17;
            CubeBottom = CubeBottom17;
            CubeRight = CubeRight17;
            CubeTop = CubeTop17;
            cCube = 17;
            break;
        }
        case 17:
        {
            vCubeRect = vCubeRect18;
            CubeLeft = CubeLeft18;
            CubeBottom = CubeBottom18;
            CubeRight = CubeRight18;
            CubeTop = CubeTop18;
            cCube = 18;
            break;
        }
        case 18:
        {
            vCubeRect = vCubeRect19;
            CubeLeft = CubeLeft19;
            CubeBottom = CubeBottom19;
            CubeRight = CubeRight19;
            CubeTop = CubeTop19;
            cCube = 19;
            break;
        }
    }
}
